package com.megvii.koala.tv.net;

import com.android.volley.Request;
import com.android.volley.Response;
import com.megvii.corelib.net.MegviiHttpManager;
import com.megvii.koala.tv.data.ServerManager;
import com.megvii.koala.tv.net.tv.GetDisplayConfigRequest;
import com.megvii.koala.tv.net.tv.GetDisplayConfigResponse;
import com.megvii.koala.tv.net.tv.GetScreenListRequest;
import com.megvii.koala.tv.net.tv.GetScreenListResponse;
import com.megvii.koala.tv.net.tv.GetThemeListRequest;
import com.megvii.koala.tv.net.tv.GetThemeListResponse;
import com.megvii.koala.tv.net.tv.SetDeviceInfoRequest;
import com.megvii.koala.tv.net.tv.SetDeviceInfoResponse;
import com.megvii.koala.tv.net.tv.SetDisplayConfigRequest;
import com.megvii.koala.tv.net.tv.SetDisplayConfigResponse;

import java.util.List;

/**
 * Created by linyue on 16/1/25.
 */
public class TVNetAPI
{
    private static MegviiHttpManager httpManager;

    private static ServerManager serverManager;

    public static void init(MegviiHttpManager httpManager, ServerManager serverManager)
    {
        TVNetAPI.httpManager = httpManager;
        TVNetAPI.serverManager = serverManager;
    }

    private static void resolveUrlBase()
    {
        httpManager.setUrlBase(serverManager.getAddress());
    }

    public static void requestGetThemeList(String device_token, Object callbackInstance,
            Response.ErrorListener errorListener)
    {
        resolveUrlBase();
        GetThemeListRequest request = new GetThemeListRequest(device_token);
        httpManager.requestJson(Request.Method.GET, request, GetThemeListResponse.class,
                callbackInstance, errorListener);
    }

    public static void requestGetScreenList(String boxToken, Object callbackInstance,
            Response.ErrorListener errorListener)
    {
        resolveUrlBase();
        GetScreenListRequest request = new GetScreenListRequest(boxToken);
        httpManager.requestJson(Request.Method.GET, request, GetScreenListResponse.class,
                callbackInstance, errorListener);
    }

    public static void requestSetDisplayConfig(String boxToken, String deviceToken,
            List<Integer> screens, int videoScreen, Object callbackInstance,
            Response.ErrorListener errorListener)
    {
        resolveUrlBase();
        SetDisplayConfigRequest request = new SetDisplayConfigRequest(boxToken, deviceToken,
                screens, videoScreen);
        httpManager.requestMultipart(Request.Method.POST, request, SetDisplayConfigResponse.class,
                callbackInstance, errorListener);
    }

    public static void requestSetDeviceInfo(String deviceToken, String city,
            Object callbackInstance, Response.ErrorListener errorListener)
    {
        resolveUrlBase();
        SetDeviceInfoRequest request = new SetDeviceInfoRequest(deviceToken, city);
        httpManager.requestJson(Request.Method.POST, request, SetDeviceInfoResponse.class,
                callbackInstance, errorListener);
    }

    public static void requestGetDisplayConfig(String deviceToken, Object callbackInstance,
                                               Response.ErrorListener errorListener){
        resolveUrlBase();
        GetDisplayConfigRequest request = new GetDisplayConfigRequest(deviceToken);
        httpManager.requestJson(Request.Method.GET,request, GetDisplayConfigResponse.class,
                callbackInstance, errorListener);
    }
}
